<?php
include '../controllers/TagController.php';
$tags = getAllTags ();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../js/tagmanager.js"></script>
</head>
<body>
	<a href='../index.php'>返回首页</a>
	<hr />
	<table border='2' rules='rows' cellpadding='8%' align='center'
		width='50%'>
		<tr>
			<th colspan="2"><h2>添加标签</h2></th>
		</tr>
		<tr>
			<th>标签名</th>
			<td><input id="tagname" type="text" size="60"></input></td>
		</tr>
		<tr>
			<th>父标签</th>
			<td><select id="supertag">
					<option value="0">一级标签</option>
					<?php
					$tagCount = count ( $tags );
					for($i = 0; $i < $tagCount; $i ++) {
						$tag = $tags [$i];
						echo "<option value='" . $tag->getTagId () . "'>" . $tag->getName () . "</option>";
					}
					?>
			</select></td>
		</tr>
		<tr align="center">
			<td colspan="2"><input type="button" value="添加标签" onclick="addTag();"></input></td>
		</tr>
	</table>
	<br />
	<br />
	<table border='2' rules='all' cellpadding='8%' align='center'
		width='50%'>
		<tr>
			<th colspan="2"><h2>标签列表</h2></th>
		</tr>
		<tr>
			<th>一级标签</th>
			<th>二级标签</th>
		</tr>
		<?php
		$tagCount = count ( $tags );
		for($i = 0; $i < $tagCount; $i ++) {
			$tag = $tags [$i];
			$subTags = $tag->getSubTags ();
			echo "<tr>";
			
			if (count ( $subTags ) > 0) {
				echo "<td rowspan=" . count ( $subTags ) . ">" . $tag->getName () . "<input type='button' value='删除' onclick='deleteTag(".$tag->getTagId().");'></input></td>";
				$subTag0 = $subTags [0];
				echo "<td>" . $subTag0->getName () . "<input type='button' value='删除' onclick='deleteTag(".$subTag0->getTagId().");'></input></td>";
			} else {
				echo "<td>" . $tag->getName () . "<input type='button' value='删除' onclick='deleteTag(".$tag->getTagId().");'></input></td>";
				echo "<td></td>";
			}
			echo "</tr>";
			
			$subTagCount = count ( $subTags );
			for($j = 1; $j < $subTagCount; $j ++) {

				echo "<tr>";
				$subTag = $subTags [$j];
				echo "<td>" . $subTag->getName () . "<input type='button' value='删除' onclick='deleteTag(".$subTag->getTagId().");'></input></td>";
				echo "</tr>";
			}
		}
		?>
	</table>
</body>
</html>